/*
 * @Author: NJ_1098 xiabaoxin
 * @Date: 2025-02-11 15:10:21
 * @LastEditors: NJ_1098 xiabaoxin
 * @LastEditTime: 2025-02-14 09:54:22
 * @Description: 账单模型层
 */
const { DataTypes } = require("sequelize");
const sequelize = require("../db/sequelize");

// 创建模型(模型 BillModel -> 表 t_bill)
// sequelize自动创建并管理id（主键，自增）
const BillModel = sequelize.define(
  "BillModel",
  {
    id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
      comment: "id，自增",
    },
    bid: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: true,
      comment: "账单id",
    },
    uid: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: false,
      comment: "用户uid（创建者）",
    },
    name: {
      type: DataTypes.STRING,
      allowNull: false,
      unique: false,
      comment: "账单名称",
    },
    sum_income: {
      type: DataTypes.INTEGER,
      allowNull: true,
      unique: false,
      comment: "账单总收入",
    },
    sum_expenses: {
      type: DataTypes.INTEGER,
      allowNull: true,
      unique: false,
      comment: "账单总支出",
    },
    zodiac: {
      type: DataTypes.STRING,
      allowNull: true,
      unique: false,
      comment: "生肖",
    },
    actors: {
      type: DataTypes.STRING,
      allowNull: true,
      comment: "协作者uid",
    },
  },
  {
    // 申明数据库表名，否则会按照sequelize标准
    tableName: "t_bill",
    // sequelize默认使用并在表中生成createdAt和updatedAt，是否默认
    timestamps: true,
    // 将createdAt改名为create_time
    createdAt: "create_time",
    // 将updatedAt改名update_time
    updatedAt: "update_time",
  }
);

// 阻止sequelize自动生成并管理的字段（id）
// UserModel.removeAttribute("id");
// 强制同步数据库（创建数据表）
// BillModel.sync({ force: true });

module.exports = BillModel;
